#include "matrix_float.h"
#include <iostream>
#include <vector>
using namespace std;

matrix_float::matrix_float(void)
{
	create_matrix(0, 0);
}

matrix_float::matrix_float(int r, int c)
{
	create_matrix(r, c);
}

matrix_float::~matrix_float(void)
{
	delete_matrix();
}

void matrix_float::create_matrix(int r, int c)
{
	if(r == 0 && c == 0)
	{
		mptr = nullptr;
		r_size = 0;
		c_size = 0;
	}
	else
	{
		mptr = new float*[r];
		for(int i=0; i < r; i++)
		{
			mptr[i] = new float[c];
		}
		r_size = r;
		c_size = c;
	}
}

void matrix_float::delete_matrix()
{
	for(int i=0; i < r_size; i++)
	{
		delete[] mptr[i];
		mptr[i] = nullptr;
	}
	delete[] mptr;
	mptr = nullptr;
	r_size = 0;
	c_size = 0;
}

void matrix_float::set(float value, int r, int c)
{
	if((r >= 0) && (r < r_size) && (c >= 0) && (c < c_size))
	{
		mptr[r][c] = value;
	}
	else
	{
		cout << "ERROR" << endl;
	}
}

void matrix_float::read_from_keyboard()
{
	cout << "Input " << r_size << "x" << c_size << " float values:\n";
	for(int i=0; i < r_size; i++)
	{
		for(int j=0; j < c_size; j++)
		{
			cin >> mptr[i][j];
		}
	}
}

void matrix_float::print()
{
	cout << "matrix contains:" << endl;
	for (int r=0; r < r_size; r++)
	{
		cout << "[";
		for (int c=0; c < c_size; c++)
		{
			cout << mptr[r][c];
			if (c < (c_size - 1)) 
			{
				cout << ", ";
			}
		}
		cout << "]\n";
	}
}

